﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.baseBLL;

namespace dhSystemBLL.basicData
{
   public class modulAaccessBLL
    {
       private modulAaccessTableAdapter  _modulAaccessAdapter = null;
       private modulAaccessTableAdapter modulAaccessAdapter
        {
            get
            {
                if (_modulAaccessAdapter == null) _modulAaccessAdapter = new modulAaccessTableAdapter ();
                return _modulAaccessAdapter;
            }
        }
        /// <summary>
        /// 查询模块权限表格
        /// </summary>
        /// <returns></returns>

       public sysDataSet.modulAaccessDataTable  getmodulAaccessAll()
        {
            try
            {
                return modulAaccessAdapter.GetDatamodulAaccessAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 根据模块编号查询表
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>

       public sysDataSet.modulAaccessDataTable getmodulAaccessAll(string moduleNum)
        {
            try
            {

                return modulAaccessAdapter.GetDatamodulAaccessByNum(moduleNum );
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
       /// <summary>
       /// 根据权限编号查询表
       /// </summary>
       /// <param name="groupNum"></param>
       /// <returns></returns>

       public sysDataSet.modulAaccessDataTable getmodulAaccessAllBygroupNum(string groupNum, string moduleNum)
       {
           try
           {

               return modulAaccessAdapter.GetDatamodulAaccessBygroupNum(groupNum, moduleNum);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }



        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int modulAaccessInsert(modulAaccessModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
               
                modulAaccessDAL modulAaccess = new modulAaccessDAL(tn, conn);
                modulAaccess.modulAaccessInsert(row);

                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int modulAaccessUpdate(modulAaccessModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                modulAaccessDAL modulAaccess = new modulAaccessDAL(tn, conn);
                modulAaccess.modulAaccessUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

       public int modulAaccessDel(string moduleNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                modulAaccessDAL modulAaccess = new modulAaccessDAL(tn, conn);
                modulAaccess.modulAaccessDel(moduleNum );
               
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
       
    }
}
